home *** CD-ROM | disk | FTP | other *** search
- :
- #BEGIN_CM_SCRIPTLIB
- #
- # Standard CM script function library
- # baselib v1.2
- #
-
- PATH=/bin:/usr/bin:/etc:.
- LANG=english_us.ascii # Used when scripts are internationalized.
- export PATH LANG
-
- TMPFILE=/tmp/tmp$$ # Define a temporary file for use if necessary.
- TMPFILE1=/tmp/tmp1$$ # Define a temporary file for use if necessary.
- TMPFILE2=/tmp/tmp2$$ # Define a temporary file for use if necessary.
-
- # Define return values.
- : ${OK=0} ${FAIL=1} ${STOP=10}
-
- #
- # Print an error message.
- #
- error() {
- echo "\nError: $*" >&2
- return 0
- }
-
- #
- # Prompt for yes or no answer - returns non-zero for no.
- #
- getyn() {
- while echo "$* (y/n) \c"
- do read yn rest
- case $yn in
- [yY]) return $OK ;;
- [nN]) return $FAIL ;;
- *) error "Please answer y or n" ;;
- esac
- done
- return 0
- }
-
- #
- # prdrel: given a prd value, return the release number of that
- # product in the variable PRDREL.
- # Return 0 if release is sucessfully gotten, return 1 if
- # the release cannot be gotten.
- #
- PRDREL1="Checking for requested release information..."
- prdrel() {
-
- _pd="$1"
- [ -n "${_pd}" ] || return 1
- PRDREL=""
- # tmp file name
- _prtmp=/tmp/pr$$
-
- if [ -f /etc/perms/${_pd} ]
- then
- PRDREL=`sed -n '/^#rel=/s///p' /etc/perms/${_pd}` || return 1
- else
- # There is no permlist with <prd> as its name, so search for
- # permlists looking for appropriate #prd=... entry.
- # Ignore update p'lists here. This code handles products
- # with several p'lists, primarily the OS and DS.
- # Pipe thru sort -r to get the highest rel first, and
- # put results into temporary file. (Ideally would pipe
- # them into 'read PRDREL', but this doesn't work under sh.)
- echo "$PRDREL1"
- : >${_prtmp} # Clear temporary file.
- for _ff in /etc/perms/*
- do
- [ -f ${_ff} ] || continue # Process regular files only
- _p=
- _u=
- _r=
- eval `sed -n '/^#rel=/s//_r=/p
- /^#upd=/s//_u=/p
- /^#prd=/s//_p=/p
- /^[A-Z]/q
- ' ${_ff} ` 2>/dev/null
- # If permlist prd matches wanted one, and it is not an upd,
- # use rel= value.
- [ -z "${_u}" -a "${_p}" = "${_pd}" ] && {
- echo ${_r}
- }
- done | sort -r > ${_prtmp} 2>/dev/null
-
- [ -s ${_prtmp} ] && PRDREL=`sed 1q ${_prtmp}`
- rm -f ${_prtmp} 2>/dev/null # Clean up tmp file.
- fi
-
- # Check if PRDREL has been set, return 1 if not.
- [ -z "$PRDREL" ] && return 1
- return 0
- }
-
- #
- #query the user for a responce.
- #a simpler system than prompt, use prompt for
- #more sophisticated uses.
- #q or Q returns fail, anything else return ok.
- #ARGS: <string>, string to print when asking for a responce
- #$OK means expression has been resolved or answer is given
- #$FAIL means quit has been selected
- #
- respond() {
- while echo "\n${*}\nRespond or enter q to quit: \c"
- do read answer
- case $answer in
- Q|q) return $FAIL ;;
- "") # on a return key return $OK
- answer="RETURNKEY"
- return $OK ;;
- *) # on anything else return $OK
- return $OK ;;
- esac
- done
- return $OK
- }
-
- #
- # SHOULD BE USED WITH EVERY INSTALLATION SCRIPT
- #
- # Set the variable $prdperm to /etc/perms/$PRDVALUE or ./tmp/perms/$PRDVALUE
- # If the permlist is found, the values for set, prd, ver, typ, rel,
- # and upd are set from the permlist.
- # Also determine the OS type, xenix or unix, and set systype accordingly.
- #
- # sets following information in exported variables
- # OSREL: x.x.xy OSTYPE: unix|xenix OSBUS: isa|mc
- # OSPRD: <prd value> OSMCH: <os machine type>
- # echo "OS Release: $OSREL OS Type: $OSTYPE OS Bus: $OSBUS"
- # echo "OS PRD Value: $OSPRD OS Machine Type: $OSMCH"
- #
- SETVARS1="Permlist not found"
- SETVARS2="Failed to set values from"
- SETVARS3="Incorrect prd value in"
-
- # Variables set by setvars.
- prdperm=
- fixperm=fixperm
- brand=brand
- set=
- prd=
- typ=
- rel=
- ser=
- upd=
- systype=unknown
-
- setvars() {
-
- # Locate fixperm, brand, and the permlist.
- for _i in /etc ./tmp
- do
- [ -f "$_i/fixperm" ] && fixperm=$_i/fixperm
- [ -f "$_i/brand" ] && brand=$_i/brand
- [ -f "$_i/perms/$PRDVALUE" ] && prdperm=$_i/perms/$PRDVALUE
- done
-
- [ "$prdperm" ] || {
- echo "Warning: $PRDVALUE $SETVARS1" >&2
- return 1
- }
-
- # Get the operating system type:
- case `uname -r` in
- 2.*) systype=xenix
- ;;
- 3.*) systype=unix
- ;;
- *) systype=unknown
- ;;
- esac
-
- #
- # OS variables setting
- # OSREL: x.x.xy OSTYPE: unix|xenix OSBUS: isa|mc
- # OSPRD: <prdvalue> OSMCH: os mch type
- #
- OSTYPE=$systype
- case "$OSTYPE" in
- unix)
- eval `sed -n '/^#prd=/s/#//p
- /^#typ=/s/#//p
- /^#rel=/s/#//p' /etc/perms/rtsmd` > /dev/null 2>&1
- OSREL=$rel
- OSPRD=$prd
- OSMCH=$typ
- if [ -r /dev/mcapos ]
- then
- if grep mcapos /etc/perms/rtsmd > /dev/null 2>&1
- then
- OSBUS=mc
- fi
- else
- OSBUS=isa
- fi
- ;;
- xenix)
- eval `sed -n '/^#prd=/s/#//p
- /^#typ=/s/#//p
- /^#rel=/s/#//p' /etc/perms/inst` > /dev/null 2>&1
- OSREL=$rel
- OSPRD=$prd
- OSMCH=$typ
- var=`expr $OSMCH : '.*\(..\)$'`
- if [ "$var" = "MC" -o "$var" = "PS" ]
- then
- OSBUS=mc
- else
- OSBUS=isa
- fi
- ;;
- *)
- OSREL=unknown
- OSTYPE=unknown
- OSBUS=unknown
- OSPRD=unknown
- OSMCH=unknown
- ;;
- esac
-
- export OSREL OSTYPE OSBUS OSPRD OSMCH
- # Clear these vars before they are used below.
- prd=
- rel=
- typ=
-
- # Extract product info from the permlist.
- eval `sed -n '/^#set=/s/#//p
- /^#prd=/s/#//p
- /^#typ=/s/#//p
- /^#rel=/s/#//p
- /^#ser=/s/#//p
- /^#upd=/s/#//p' $prdperm` || echo "\n$SETVARS2 $prdperm" >&2
-
- # Check the prd value read from the permlist for correctness.
-
- case "$prd" in
- "$PRDVALUE") return 0
- ;;
- *) echo "\n$SETVARS3 $prdperm" >&2
- return 1
- ;;
- esac
-
- return 0
- }
-
- #
- # tarcomp: Determines whether the system 'tar' is capable of decompressing.
- # files automatically. The command tar is used unless another is
- # specified in the variable TARPROG.
- # Returns 'true' (0) if the tar program can decompress, 'fail' if it cannot.
- #
- tarcomp() {
-
- # Set TARPROG to default of tar if not set.
- : ${TARPROG:=tar}
- tctmp=/tmp/tc$$ # Name for tmp files.
-
- # Eminently compressible data to go into file. (60 'a's)
- _ptrn="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
-
- echo ${_ptrn} | compress -F > $tctmp.A # Compress data.
-
- # Tar to an archive file, with headers set to indicate compression.
- ${TARPROG} Cf $tctmp.T $tctmp.A 2>/dev/null || {
- rm -rf $tctmp.*
- return 1
- }
-
- # Now restore original file from archive - it should automagically
- # be decompressed.
- rm -f $tctmp.A
- ${TARPROG} xf $tctmp.T 2>/dev/null || {
- rm -rf $tctmp.*
- return 1
- }
-
- # Compare it to the original data.
- echo ${_ptrn} | cmp -s - $tctmp.A 2>/dev/null || {
- rm -rf $tctmp.*
- return 1
- }
-
- # If we got here, the two compared equal, which
- # implies that the compress/decompress cycle worked.
- rm -rf $tctmp.*
- return 0
- }
-
- #
- # Standard CM script function library
- # configlib V1.0
- # Contains: baselib, specificlib
- #
-
- #
- # Standard CM script function library
- # specificlib v1.4
- # contains: baselib
- #
-
- #
- # backs up all files based on permslist that is on the
- # path given as arg1. files will be backed up in the STANDARD location
- # ARG1: PRDVALUE of product so files can be placed in the standard location
- # Usage: allbackup <prdvalue>
- #
- ALLBACKUP1="Creating list of files to be overwritten..."
- ALLBACKUP2="
- You now have the opportunity to backup
- all files that may be overwritten during this
- product's installation.
- You can restore these files if required.
- You will need to verify that you have
- enough disk space available if you
- choose to backup. This product puts its
- backup files in the following location: "
-
-
- allbackup() {
- PERMARG=$1
-
- cd /
- rm -f $TMPFILE
- echo "$ALLBACKUP1"
- # -l lists both files and directories in the permlist.
- fixperm -u PERM -l /tmp/perms/$PERMARG > $TMPFILE
- if [ -s "$TMPFILE" ]
- then
- echo "$ALLBACKUP2"
- echo "/usr/lib/custom/${PERMARG}/backup\n"
- onlinebackup $PERMARG $TMPFILE || return 1
- rm -f $TMPFILE
- fi
- return $OK
- }
-
- #
- # onlinebackup
- #
- # This function takes as arguments the prd of the product being installed
- # and the name of a file listing files to be backed-up. The list of
- # files is checked, and those files that exist on the system will
- # be saved under the backup directory for the product
- # ARG1: PRDVALUE of product so files can be placed in the standard location
- # ( /usr/lib/custom/$PRDVALUE/backup )
- # ARG2: Name of a file listing files that are to be backed-up (one name
- # per line in the file; these filenames should be pathnames relative
- # to /, not absolute pathnames). This list may include
- # directory names; if directories are included, they will be
- # created under the backup directory with their own mode/uid/gid.
- # Directories not listed will be created as necessary under the
- # backup directory, using the current default mode/uid/gid.
- # Usage: onlinebackup <prdvalue> <file list path>
- #
- #ONLINE0="Creating backup list..."
- ONLINE1="Do you want to see the file list ?"
- ONLINE2=" <Press Return to Continue>"
- ONLINE3="
- It is estimated that you will need the
- following amount of space to backup
- the selected files online.
- Computing estimate
- in 512 byte blocks...
- "
- ONLINE4="Do you want to backup these files ?"
- ONLINE5="There are no existing files that require backing up."
- onlinebackup() {
- PRDARG=$1
- LISTARG=$2
- # Check that both are non-null
- : ${PRDARG:?} ${LISTARG:?}
-
- cd /
- rm -rf $TMPFILE2
- echo " "
- # echo "$ONLINE0"
- cat $LISTARG | while read file
- do
- [ -r "$file" ] && echo $file >> $TMPFILE2
- done
- if [ -s "$TMPFILE2" ]
- then
- getyn "$ONLINE1" && pg -p "$ONLINE2" $TMPFILE2
- echo "$ONLINE3"
- cat $TMPFILE2 | cpio -ocB | dd of=/dev/null bs=10b > /dev/null 2>&1
- echo " "
- getyn "$ONLINE4" && {
- mkdir /usr/lib/custom/${PRDARG} > /dev/null 2>&1
- mkdir /usr/lib/custom/${PRDARG}/backup > /dev/null 2>&1
- cat $TMPFILE2 | cpio -pdmuv /usr/lib/custom/${PRDVALUE}/backup || return 1
- }
- rm -rf $TMPFILE2
- else
- echo "$ONLINE5"
- fi
- return 0
- }
-
- #END_CM_SCRIPTLIB
-
- # Check the installation status of the product with prd=$PRDVALUE
- preinst_check() {
-
- set -- `who -r`
- case $3 in
- S) : Feeling groovy
- ;;
- *) cat >&2 <<HERE
- This SLS should be installed in single user mode. Please
- shut the system down before running custom
- HERE
- return 1
- ;;
- esac
-
- return 0
- }
-
- #MAIN
-
- PRDVALUE=mmdfsls1
- export PRDVALUE
-
- # get permlist information
- cd /
-
- setvars
-
- preinst_check || {
- echo "There has been an error in the prep script."
- echo "Aborting installation..."
- exit 1
- }
-
- # optional backup of all files that may potentially be overwritten
- echo " "
- allbackup $PRDVALUE || {
- echo "Warning: Unable to backup complete file list"
- getyn "Do you want to continue with Installation ?" || exit $FAIL
- }
-
- respond "Press return to continue" || exit 1
-
- exit 0
-